import { reqGetCode, reqRegister } from "@/api";

const actions = {
    async getCode({ commit }, phone) {
        let result = await reqGetCode(phone);
        if (result.code == 200) {
            commit("GetCode", result.data)
            // 由于可能需要用于判断是否成功，因此需要又成功与失败的返回
            return "ok"
        } else {
            return Promise.reject(new Error("Failed!"))
        }
    },

    // eslint-disable-next-line no-unused-vars
    async register({ commit }, data) {
        let result = await reqRegister(data)
        console.log(result);
        if (result.code == 200) {
            return "ok"
        } else {
            return Promise.reject(new Error("Failed!"))
        }
    }
};

const mutations = {
    GetCode(state, code) {
        state.code = code
    }
};

// 对于想要的数据层数太多，就需要在getters里面准备好，而且还要考虑到没请求到数据的情况
const getters = {

};

const state = {
    code: ''
};

export default {
    actions,
    mutations,
    getters,
    state,
};
